<template>
    <!--引入布局-->
    <el-container class="home-container">
        <!--头部-->
        <el-header>
            <!--首页-->
            <div>
                <img src="../assets/logo.jpg" alt/>
                <span>云溪商城管理系统</span>
            </div>
            <el-button type="info" @click="logout">安全退出</el-button>
        </el-header>
        <!--主体-->
        <el-container>
            <!--侧边布局-->
            <el-aside :width="isCollapse ?'64px':'200px'">
                <!--伸缩按钮-->
                <div class="toggle-button" @click="toggleCollapase">|||</div>
                <!--侧边栏-->
                <el-menu background-color="#545c64" text-color="#fff" active-text-color="#409eff" unique-opened :collapse="isCollapse"  @select="handleSelect">
                    <el-menu-item index="1">
                        <i class="iconfont icon-shouye"></i>
                        <span slot="title">首页</span>
                    </el-menu-item>

                    <el-submenu index="2" v-if="status == 0">
                        <template slot="title">
                            <i class="iconfont icon-shangpin"></i>
                            <span>商品</span>
                        </template>
                        <el-menu-item-group>
                            <el-menu-item index="1-1" class="iconfont icon-shangpinliebiao">  商品列表</el-menu-item>
                            <el-menu-item index="1-3" class="iconfont icon-shangpinfenlei">  商品分类</el-menu-item>
                        </el-menu-item-group>
                    </el-submenu>
                    <el-submenu index="3">
                        <template slot="title">
                            <i class="iconfont icon-dingdan"></i>
                            <span>订单</span>
                        </template>
                        <el-menu-item-group >
                            <el-menu-item index="2-1" class="iconfont icon-dingdan1">  订单列表</el-menu-item>
                            <el-menu-item index="2-2" class="iconfont icon-tuihuo" v-if="status==0">  退货处理</el-menu-item>
                        </el-menu-item-group>
                    </el-submenu>

                    <el-menu-item index="4">
                        <i class="iconfont icon-gerenxinxi"></i>
                        <span slot="title" >个人信息</span>
                    </el-menu-item>
                </el-menu>
            </el-aside>
            <!--主体内容-->
            <el-main class="el-main">
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
    export default {
        data(){
            return{
                isCollapse:false, //伸缩
                status: sessionStorage.getItem("status")
            }
        },
        // onload 事件
        created() {

        },

        methods: {
            logout(){
                // 安全退出
                window.sessionStorage.clear(); //清除session
                this.$router.push("/login");  //回到首页
            },

            //控制伸缩
            toggleCollapase(){
                this.isCollapse = !this.isCollapse;
            },
            //保存路径
            saveNavState(activePath){
                window.sessionStorage.setItem('activePath',activePath); // 存放到session里
                this.activePath = activePath;
            },
            handleSelect(key, keyPath) {
                console.log(key, keyPath);
                if(key=="1")
                    this.$router.push("/shop")
                if(key=="2-1")
                    this.$router.push("/home/torder")
                if(key=="2-2")
                    this.$router.push("/home/refund")
                if(key=="1-1")
                    this.$router.push("/home/tproduct")
                if(key=="1-3")
                    this.$router.push("/home/pmscategory")
            }

        },
    };
</script>

<style lang="less" scoped>

    .home-container{
        height: 100%;

    }

    .el-header{
        background-color: #373d41;
        display: flex;
        justify-content: space-between;
        padding-left: 0%;  // 左边界
        align-items: center;
        color: #fff;
        font-size: 20px;
        display: flex;
        align-items: center;
        > div { //左侧div加布局
            display: flex;
            align-items: center;
            span {
                margin-left: 15px;
            }
        }

    }

    .el-aside {
        background-color: #333744;
        .el-menu{
            border-right: none;// 对其右边框
        }
    }
    .el-main{
        background-color: #eaedf1;
    }

    img{
        width: 55px;
        height: 55px;
    }
    .iconfont{
        margin-right: 10px;
    }
    .toggle-button{
        background-color:#4A5064;
        font-size: 10px;
        line-height: 24px;
        color:#fff;
        text-align: center;
        letter-spacing: 0.2em;
        cursor: pointer;
    }

</style>
